package island.gotenyama.wand.field;

import island.gotenyama.wand.annotation.FieldDefinition;
import island.gotenyama.wand.annotation.NotNull;
import island.gotenyama.wand.annotation.Length;
import island.gotenyama.wand.annotation.TableDefinition;
import island.gotenyama.wand.bean.AField;
import island.gotenyama.wand.enums.DBFieldType;
import island.gotenyama.wand.enums.JavaFieldType;
import island.gotenyama.wand.exception.FatalException;

import java.lang.reflect.Field;

/**
 * ロイターニュースのフィールドを定義する。
 * 
 * @author tk
 */
@TableDefinition(name = "reuters_news", nameJp = "ロイターニュース", hasACmnField = false)
public enum ReutersNewsField implements AField {

	@NotNull
	@FieldDefinition(name = "id", nameJp = "ID", typeDB = DBFieldType.INTEGER, typeJava = JavaFieldType.LONG)
	ID,
	
	@NotNull
	@Length(max = 300)
	@FieldDefinition(name = "news_text", nameJp = "説明", typeDB = DBFieldType.VARCHAR, typeJava = JavaFieldType.STRING)
	NEWS_TEXT;
	
	@Override
	public Field getField() {
		try {
			return PasswordHintField.class.getDeclaredField(name());
		} catch (NoSuchFieldException e) {
			throw new FatalException("No Field.", e);
		}
	}

	@Override
	public FieldDefinition getFieldDefinition() {
		return getField().getAnnotation(FieldDefinition.class);
	}
}
